package com.example.terminalservice.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author 28142
 * @description 自定义返回类型
 * @date 2023/8/4 16:49
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private Integer code;
    private String msg;
    private T data;

    public static <T> Result<T> success() {
        return new Result(CodeEnum.CODE_200.getCode(), CodeEnum.CODE_200.getMsg(), null);
    }

    public static <T> Result<T> success(T data) {
        return new Result(CodeEnum.CODE_200.getCode(), CodeEnum.CODE_200.getMsg(), data);
    }

    public static <T> Result<T> success(String msg, T data) {
        return new Result(CodeEnum.CODE_200.getCode(), msg, data);
    }

    public static <T> Result<T> success(Integer code, String msg, T data) {
        return new Result(code, msg, data);
    }

    public static <T> Result<T> error() {
        return new Result(CodeEnum.CODE_400.getCode(), CodeEnum.CODE_400.getMsg(), null);
    }

    public static <T> Result<T> error(String msg) {
        return new Result(CodeEnum.CODE_400.getCode(), msg, null);
    }

    public static <T> Result<T> error(CodeEnum codeEnum) {
        return new Result(codeEnum.getCode(), codeEnum.getMsg(), null);
    }

    public static <T> Result<T> error(String msg, T data) {
        return new Result(CodeEnum.CODE_400.getCode(), msg, data);
    }

    public static <T> Result<T> error(Integer code, String msg) {
        return new Result(code, msg, null);
    }

    public static <T> Result<T> error(Integer code, String msg, T data) {
        return new Result(code, msg, data);
    }
}
